<?php require_once 'header.php';?>    
<!-- DataTables Responsive CSS -->
    <link href="sb2/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                        <?php echo XXF_BACK?>
                            课程管理 <br>
                            [
                            <input type="text" id="kname" name="kname" placeholder="课程名称"  title="课程名称" style="font-size: 10px;width:180px;">
                            <input type="text" id="jiaocai" name="jiaocai" placeholder="使用教材"  title="使用教材" style="font-size: 10px;width:180px;">
                            <input type="hidden" id="keshi" name="keshi" placeholder="课时数"  title="课时数" style="font-size: 10px;width:120px;">
                            <select id="ktype" style="display:none;">
                            	<option value="普通课">普通课</option>
                            	<option value="上机课">上机课</option>
                            	<option value="实践课">实践课</option>
                            </select>
                            <input type="button" id="add" value="添加" onclick="add()"> ]
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>课程名称</th>
                                        <th>教材</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                	<?php
                                	$i=0;
                                	foreach ($result as $row){$i++;
                                	?>
                                    <tr class="<?php echo $i%2==0?"even":"odd";?> gradeA" id='<?php echo $row['id'];?>'>
                                        <td><?php echo $row['kname'];?></td>
                                        <td><?php echo $row['jiaocai'];?></td>
                                        <td><a href="javascript:del(<?php echo $row['id']?>)">删除</a></td>
                                    </tr>
                                	<?php 
                                	}
                                	?>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            
            <!-- /.row -->
             </div>
        </div>
        <!-- /#page-wrapper -->
  </div>
        <!-- DataTables JavaScript -->
<?php require_once 'bottom.php';?>
    <script src="sb2/vendor/datatables/js/jquery.dataTables.js"></script>
    <script src="sb2/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="sb2/vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true,
            "aaSorting": [[ 0, "desc" ]],
            "aLengthMenu": [ 100,50,25,10]
        });
        $("#shengri").click(function(){$(this).xrili();});
        $("#zhuanyeage").click(function(){$(this).xrili();});
        $("#jiaoxueage").click(function(){$(this).xrili();});
    });
   
    function del(pid){
		$.xconfirm("删除后无法恢复，确定要删除此条记录么？",function(data){
 			if(data){
				$.xloading(1);
				var post=function(){
    				$.post("pxy_kcset",{type:'del',pid:pid},function(data1){
    					if(data1==0){
    						$.xloading(0);
    						$.xalert("删除失败");
    					}else{
    						window.location.reload();
    					}
    				}).error(function(){
						post();
        			}); 
				}
				post();
			} 
		});
    }
    function add(){
    	var kname = $("#kname").val();
    	var jiaocai = $("#jiaocai").val();
    	var keshi = $("#keshi").val();
    	var ktype = $("#ktype").val();
 		if(kname.length<1||jiaocai.length<1){
			$.xalert("请将信息填写完整！");return false;
 	 	}
    	$.xconfirm("确定添加？",function(data){
 			if(data){
				$.xloading(1);
				var post=function(){
    				$.post("pxy_kcset",{
    					type:'add',kname:kname,jiaocai:jiaocai,keshi:keshi,ktype:ktype
    					},function(data1){
        					if(data1==0){
        						$.xloading(0);
        						$.xalert("添加失败");
        					}else{
        						window.location.reload();
        					}
        				}).error(function(){
        				post();
            			}); 
				}
				post(); 
			} 
		});
    }    
    </script>